<style>
    .search_user,.search_course,.search_distributor{cursor:pointer}
    .search_input_clear{position: absolute;right: 21px; top: 4px; font-size: 24px; width: 20px; height: 20px; color: red;display: none;}
</style>
<!-- 搜索员工 -->
<div class="modal fade" id="search_user_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog " role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">员工搜索</h4>
            </div>
            <div class="modal-body">
                <div class="form-group form-horizontal form-style">
                    <div class="row m-b">
                        <label class="col-sm-3 control-label">员工昵称/ID</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control user_keywords" value="">
                        </div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-primary user_search">搜索</button>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered table-hover dataTables-example">
                    <thead>
                    <tr class="tb-title">
                        <th class="text-center">员工ID</th>
                        <th class="text-center">昵称</th>
                        <th class="text-center">状态</th>
                        <th class="text-center">注册时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<!-- 搜索经销商 -->
<div class="modal fade" id="search_distributor_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog " role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">经销商搜索</h4>
            </div>
            <div class="modal-body">
                <div class="form-group form-horizontal form-style">
                    <div class="row m-b">
                        <label class="col-sm-3 control-label">经销商昵称/ID</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control distributor_keywords" value="">
                        </div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-primary distributor_search">搜索</button>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered table-hover dataTables-example">
                    <thead>
                    <tr class="tb-title">
                        <th class="text-center">经销商ID</th>
                        <th class="text-center">昵称</th>
                        <th class="text-center">审核状态</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<!-- 搜索机构 -->
<div class="modal fade" id="search_organization_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog " role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">机构搜索</h4>
            </div>
            <div class="modal-body">
                <div class="form-group form-horizontal form-style">
                    <div class="row m-b">
                        <label class="col-sm-3 control-label">机构名称/ID</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control organization_keywords" value="">
                        </div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-primary organization_search">搜索</button>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered table-hover dataTables-example">
                    <thead>
                    <tr class="tb-title">
                        <th class="text-center">机构ID</th>
                        <th class="text-center">名称</th>
                        <th class="text-center">审核状态</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<!-- 搜索代理商 -->
<div class="modal fade" id="search_agent_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog " role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">代理商搜索</h4>
            </div>
            <div class="modal-body">
                <div class="form-group form-horizontal form-style">
                    <div class="row m-b">
                        <label class="col-sm-3 control-label">代理商名称/ID</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control agent_keywords" value="">
                        </div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-primary agent_search">搜索</button>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered table-hover dataTables-example">
                    <thead>
                    <tr class="tb-title">
                        <th class="text-center">代理商ID</th>
                        <th class="text-center">名称</th>
                        <th class="text-center">状态</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script type="application/javascript">
    $(function(){
        //显示清除id按钮
        $('.search_user,.search_distributor,.search_organization,.search_agent').after('<a href="javascript:;" title="清空" class="fa fa-close search_input_clear"></a>');
        $('.search_user,.search_distributor,.search_organization,.search_agent').parent().mouseenter(function(){
           $(this).find('.search_input_clear').show();
        }).mouseleave(function(){
            $(this).find('.search_input_clear').hide();
        });
        $('body').on('click','.search_input_clear',function(){
            $(this).siblings('input').val('').trigger("change");
        })
        //员工
        $('#search_user_modal').on('shown.bs.modal',function(e){
            $('#search_user_modal .user_keywords')[0].focus();
        });
        $('.search_user').click(function(){
            $('#search_user_modal .user_keywords').val('');
            $('#search_user_modal table tbody').empty();
            $('#search_user_modal').modal('show');
        });
        $('#search_user_modal .user_search').click(function(){
            select_user();
        });
        $('#search_user_modal .user_keywords').keyup(function(e){
            if(e.which == 13){
                select_user();
            }
        });
        //经销商
        $('#search_distributor_modal').on('shown.bs.modal',function(e){
            $('#search_distributor_modal .distributor_keywords')[0].focus();
        });
        $('.search_distributor').click(function(){
            $('#search_distributor_modal .distributor_keywords').val('');
            $('#search_distributor_modal table tbody').empty();
            $('#search_distributor_modal').modal('show');
        });
        $('#search_distributor_modal .distributor_search').click(function(){
            select_distributor();
        });
        $('#search_distributor_modal .distributor_keywords').keyup(function(e){
            if(e.which == 13){
                select_distributor();
            }
        });
        //机构
        $('#search_organization_modal').on('shown.bs.modal',function(e){
            $('#search_organization_modal .organization_keywords')[0].focus();
        });
        $('.search_organization').click(function(){
            $('#search_organization_modal .organization_keywords').val('');
            $('#search_organization_modal table tbody').empty();
            $('#search_organization_modal').modal('show');
        });
        $('#search_organization_modal .organization_search').click(function(){
            select_organization();
        });
        $('#search_organization_modal .organization_keywords').keyup(function(e){
            if(e.which == 13){
                select_organization();
            }
        });
        //代理商
        $('#search_agent_modal').on('shown.bs.modal',function(e){
            $('#search_agent_modal .agent_keywords')[0].focus();
        });
        $('.search_agent').click(function(){
            $('#search_agent_modal .agent_keywords').val('');
            $('#search_agent_modal table tbody').empty();
            $('#search_agent_modal').modal('show');
        });
        $('#search_agent_modal .agent_search').click(function(){
            select_agent();
        });
        $('#search_agent_modal .agent_keywords').keyup(function(e){
            if(e.which == 13){
                select_agent();
            }
        });
    });


    //员工
    function select_user(){
        var user_keywords = $('#search_user_modal .user_keywords').val();
        $('#search_user_modal table tbody').empty();
        $.ajax({
            url: '/user/search-list-ajax-do',
            type: 'post',
            dataType: 'json',
            data: {keywords:user_keywords},
            success: function (res) {
                var html = '<tr align="center"><td colspan=6>没有数据</td></tr>';
                if(res.code == 20000){
                    if(res.data != undefined && res.data.length > 0){
                        html = '';
                        $.each(res.data,function(i,n){
                            html += '<tr align="center"><td>'+ n.id +'</td><td><b>'+ n.nickname +'</b></td><td>'+ n.status_name +'</td><td>'+ n.create_time +'</td><td><a href="javascript:;" onclick="select_user_id('+ n.id +')" class="btn btn-xs btn-primary">选择</td></tr>';
                        });
                    }
                }
                $('#search_user_modal table tbody').html(html);
            }
        });
    }
    function select_user_id(id){
        $('#search_user_modal').modal('hide');
        $('.search_user').val(id).trigger("change");
    }
    //经销商
    function select_distributor(){
        var distributor_keywords = $('#search_distributor_modal .distributor_keywords').val();
        $('#search_distributor_modal table tbody').empty();
        $.ajax({
            url: '/distributor/search-list-ajax-do',
            type: 'post',
            dataType: 'json',
            data: {keywords:distributor_keywords},
            success: function (res) {
                var html = '<tr align="center"><td colspan=6>没有数据</td></tr>';
                if(res.code == 20000){
                    if(res.data != undefined && res.data.length > 0){
                        html = '';
                        $.each(res.data,function(i,n){
                            html += '<tr align="center"><td>'+ n.user_id +'</td><td><b>'+ n.nickname +'</b></td><td>'+ (n.is_checked == 1?'已审核':'未审核') +'</td><td>'+ n.create_time +'</td><td><a href="javascript:;" onclick="select_distributor_id('+ n.user_id +')" class="btn btn-xs btn-primary">选择</td></tr>';
                        });
                    }
                }
                $('#search_distributor_modal table tbody').html(html);
            }
        });
    }
    function select_distributor_id(id){
        $('#search_distributor_modal').modal('hide');
        $('.search_distributor').val(id).trigger("change");
    }

    //机构
    function select_organization(){
        var organization_keywords = $('#search_organization_modal .organization_keywords').val();
        $('#search_organization_modal table tbody').empty();
        $.ajax({
            url: '/organization/search-list-ajax-do',
            type: 'post',
            dataType: 'json',
            data: {keywords:organization_keywords},
            success: function (res) {
                var html = '<tr align="center"><td colspan=6>没有数据</td></tr>';
                if(res.code == 20000){
                    if(res.data != undefined && res.data.length > 0){
                        html = '';
                        $.each(res.data,function(i,n){
                            html += '<tr align="center"><td>'+ n.user_id +'</td><td><b>'+ n.name +'</b></td><td>'+ (n.is_checked == 1?'已审核':'未审核') +'</td><td>'+ n.created_at +'</td><td><a href="javascript:;" onclick="select_organization_id('+ n.user_id +')" class="btn btn-xs btn-primary">选择</td></tr>';
                        });
                    }
                }
                $('#search_organization_modal table tbody').html(html);
            }
        });
    }
    function select_organization_id(id){
        $('#search_organization_modal').modal('hide');
        $('.search_organization').val(id).trigger("change");
    }

    //代理商
    function select_agent(){
        var agent_keywords = $('#search_agent_modal .agent_keywords').val();
        $('#search_agent_modal table tbody').empty();
        $.ajax({
            url: '/agent/search-list-ajax-do',
            type: 'post',
            dataType: 'json',
            data: {keywords:agent_keywords},
            success: function (res) {
                var html = '<tr align="center"><td colspan=6>没有数据</td></tr>';
                if(res.code == 20000){
                    if(res.data != undefined && res.data.length > 0){
                        html = '';
                        $.each(res.data,function(i,n){
                            html += '<tr align="center"><td>'+ n.id +'</td><td><b>'+ n.name +'</b></td><td>'+ (n.is_delete == 1?'已删除':(n.status == 1?'已禁用':'正常')) +'</td><td>'+ n.create_time +'</td><td><a href="javascript:;" onclick="select_agent_id('+ n.id +')" class="btn btn-xs btn-primary">选择</td></tr>';
                        });
                    }
                }
                $('#search_agent_modal table tbody').html(html);
            }
        });
    }
    function select_agent_id(id){
        $('#search_agent_modal').modal('hide');
        $('.search_agent').val(id).trigger("change");
    }

</script>